package cn.agiledata.bank.transaction.service;

import java.util.List;

import cn.agiledata.bank.common.dao.SysTemplate;
import cn.agiledata.bank.common.util.Constant;
import cn.agiledata.bank.hibernateBean.SysParameter;
import cn.agiledata.bank.hibernateBean.Transaction;

public class TransactionRemit 
	extends TransactionFactoryAbstract {
	private SysTemplate sysTemplate ;

	public void setSysTemplate(SysTemplate sysTemplate) {
		this.sysTemplate = sysTemplate;
	}

	public synchronized void saveTransaction(Transaction tran) {

		//获得具体收费模式
		SysParameter withdrawFee = sysTemplate.getWithDrawFee(tran.getDebit().getId());

		if (tran.isGiveBackPayFee() == Constant.GIVEBACK_PAYFEE_Y)
		{
			tran.setAmount(
					Double.valueOf(
							String.valueOf(tran.getAmount().doubleValue()+tran.getDebitFee().doubleValue())));
			tran.setDebitFee(new Double(0));
		}
		// TODO Auto-generated method stub
		List bankList = ftd.fillRemitTransaction(tran, withdrawFee);

		//如果是未确认状态只保存一条交易记录
			getHibernateTemplate().save(tran);
			
			ahoi.updateTranHis(tran);
			
			getHibernateTemplate().saveOrUpdateAll(bankList);
			getHibernateTemplate().update(tran.getDebit());
			ahoi.update(tran.getDebit(),tran.getAmount(),tran.getDebitFee(),Constant.PAY,tran
					,tran.getCredit().getId());
	}



}
